num = int(input())
if num % 1 > 0 or num < 1000 or num > 9999:
    print('0')
    exit() 
num = str(num) 
slices = [int(num[0:2]), int(num[1:3]), int(num[2:4]),
          int(num[0:3]), int(num[1:4]),
          int(num[0:4])]
num = int(num) 
answer = 0  
for slice in slices: 
    for div in range(2, int(num**0.5)+1):
        if num % div == 0: 
            brea
    answer = max(answer, slice) 
   
